<template>
  <div>
    <div class="nav"></div>
    <div class="wrap">
      <div class="body">
        <div class="title">修改密码</div>
        <div class="line"></div>
        <div class="list">
          <img class="red" src="../../images/main/red.png" alt>
          <span class="txt">当前密码：</span>
          <input type="text" class="input" placeholder="请输入当前密码" v-model="odlPass">
        </div>
        <div class="list">
          <img class="red" src="../../images/main/red.png" alt>
          <span class="txt">新密码：</span>
          <input type="text" class="input" placeholder="请输入新密码" v-model="newPass">
        </div>
        <div class="list">
          <img class="red" src="../../images/main/red.png" alt>
          <span class="txt">确认新密码：</span>
          <input type="text" class="input" placeholder="请输入新密码" v-model="rePass">
        </div>
        <div class="save" @click="save()">保存</div>
      </div>
    </div>
  </div>
</template>
<script>
import Global from "../tool/Global.vue";
import axios from "axios";
import qs from "qs"; // 将请求转换成form 表单提交形式
export default {
  data() {
    return {
      staffInfo: {},
      newPass: "",
      rePass: "",
      odlPass: ""
    };
  },
  methods: {
    /**
     * 获取员工信息
     */
    getMans: function() {
      let that = this;
      axios({
        method: "post",
        url: `${that.$store.state.url}/sysEmployee/selectByEmpId`,
        data: qs.stringify({ id: Global.mansId })
      }).then(res => {
        console.log(res);
        if (res.data.code == 0) {
          that.staffInfo = res.data.data;
        } else {
          alert(res.data.msg);
        }
      });
    },
    save: function() {
      let that = this;
      if (that.newPass != that.rePass) {
        alert("两次密码输入不一致");
      } else if (that.odlPass != that.staffInfo.passWord) {
        alert("原密码错误！");
      } else {
        axios({
          method: "post",
          url: `${that.$store.state.url}/sysEmployee/updatePwd`,
          data: qs.stringify({
            id: Global.mansId,
            pwd: that.newPass
          })
        }).then(res => {
          console.log(res);
          if (res.data.code == 0) {
            that.$router.push({
              path: "/main/staffMan"
            });
            that.task = false;
          } else {
            alert(res.msg);
          }
        });
      }
    }
  },
  mounted() {
    this.getMans();
  }
};
</script>
<style scoped>
.nav {
  background: #353948;
  /* width: 1920px; */
  height: 111px;
}
.wrap {
  width: 90%;
  height: clac(100vh - 211px);
  background: #eceef3;
  margin: 100px auto;
}
.body {
  background: #ffffff;
  box-shadow: 0 5px 20px 0 rgba(0, 0, 0, 0.05);
  border-radius: 6px;
  /* width: 1071px; */
  height: 658px;
  margin: 0 auto;
}
.title {
  height: 115px;
  font-family: PingFangSC-Medium;
  font-size: 24px;
  color: #000000;
  letter-spacing: 0;
  line-height: 115px;
  text-align: center;
  font-weight: bold;
}
.line {
  background: #f5f5f5;
  /* width: 861px; */
  height: 3px;
  margin: 0 auto;
}
.list {
  height: 40px;
  /* margin-top: 64px; */
  font-family: PingFangSC-Medium;
  font-size: 18px;
  color: #000000;
  line-height: 40px;
  width: 500px;
  margin: 60px auto;;
}
.red {
  width: 10px;
  height: 10px;
  /* margin-left: 285px; */
}
.txt {
  width: 109px;
  display: inline-block;
  text-align: left;
  font-family: PingFangSC-Medium;
  font-size: 18px;
  font-weight: bold;
  color: #000000;
}
.input {
  background: #ffffff;
  box-shadow: inset 0 1px 3px 0 rgba(0, 0, 0, 0.5);
  width: 307px;
  height: 40px;
  margin-left: 10px;
  padding-left: 10px;
  font-family: PingFangSC-Medium;
  font-size: 18px;
  color: #888888;
  box-sizing: border-box;
}
.save {
  background: #085dab;
  width: 255px;
  height: 55px;
  text-align: center;
  font-family: PingFangSC-Medium;
  font-size: 18px;
  color: #ffffff;
  /* margin-left: 420px; */
  /* margin-top: 102px; */
  cursor: pointer;
  line-height: 55px;
  margin: 100px auto;
}
</style>
